package com.myweixin.config;

import java.io.File;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.weixin.sdk.api.ApiConfigKit;
import com.myweixin.entity.Users;
import com.myweixin.weixin.WeiXinController;

/**
 * 
 * @author liuzy
 * @since 2016年10月11日
 */
public class WeiXinConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use(new File(System.getProperty("appCfg") + "config.properties"));
		me.setDevMode(PropKit.getBoolean("wx.devMode", false));
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
		ApiConfigKit.setDevMode(me.getDevMode());
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/wx/", WeiXinController.class, "/");
	}

	@Override
	public void configPlugin(Plugins me) {
		DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("druid.jdbcUrl"), PropKit.get("druid.username"), PropKit.get("druid.password"));
		druidPlugin.set(PropKit.getInt("druid.initialSize"), PropKit.getInt("druid.minIdle"), PropKit.getInt("druid.maxActive"));
		druidPlugin.setMaxWait(PropKit.getInt("druid.maxWait"));
		druidPlugin.setTimeBetweenEvictionRunsMillis(PropKit.getInt("druid.timeBetweenEvictionRunsMillis"));
		druidPlugin.setMinEvictableIdleTimeMillis(PropKit.getInt("druid.minEvictableIdleTimeMillis"));
		druidPlugin.setFilters(PropKit.get("druid.filters"));
		druidPlugin.setValidationQuery(PropKit.get("druid.validationQuery"));
		druidPlugin.setTestWhileIdle(PropKit.getBoolean("druid.testWhileIdle"));
		druidPlugin.setTestOnBorrow(PropKit.getBoolean("druid.testOnBorrow"));
		druidPlugin.setTestOnReturn(PropKit.getBoolean("druid.testOnReturn"));
		me.add(druidPlugin);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        arp.setDevMode(PropKit.getBoolean("wx.devMode", false));
        arp.setShowSql(PropKit.getBoolean("wx.showSql", false));
        arp.setDialect(new MysqlDialect());
        arp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
        arp.addMapping("users", Users.class);
        me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		
	}

}
